package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketComment;
import com.cskaoyan.bean.MarketGoods;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.goods.bo.BasePageInfoBo;
import com.cskaoyan.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class CommentController {

    @Autowired
    CommentService commentService;

    @RequestMapping("admin/comment/list")
    public BaseRespVo list(BasePageInfoBo basePageInfoBo) {
        CommonData<MarketComment> baseRespVoCommonData = commentService.queryAllComments(basePageInfoBo);
        BaseRespVo baseRespVo = BaseRespVo.ok(baseRespVoCommonData);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

    @PostMapping("admin/comment/delete")
    public BaseRespVo delete(@RequestBody MarketComment marketComment) {
        int code = commentService.deleteComments(marketComment);
        if (code == 1) {
            BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
            baseRespVo.setErrmsg("成功");
            return baseRespVo;
        } else {
            BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
            baseRespVo.setErrmsg("Not Found");
            return baseRespVo;
        }
    }
}
